package com.songcha.sakura.download.m3u8

import android.os.Parcel
import android.os.Parcelable
import com.songcha.sakura.download.base.DownloadOption

class M3u8DownloadOption() : DownloadOption() {
     var m3u8IndexPath=""
     var episodePath=""
     var urlPath=""
     //分辨率
     var resolution=""

     var urlConverter: M3u8UrlConverter?=null
     var tsConverter: M3u8TsConverter?=null

     fun setPath(){
          m3u8IndexPath=filePath+".index"
          val idx=filePath.lastIndexOf("/")
          val tmpPath=filePath.substring(0,filePath.length-".m3u8".length)
          fileName=tmpPath.substring(tmpPath.lastIndexOf("/")+1)

          val episodePathBefore=filePath.substring(0,idx+1)
          val episodePathBehind=filePath.substring(idx+1)
          episodePath=episodePathBefore+episodePathBehind+"_0"
          uuid=episodePathBehind.substring(0,10)
          urlPath=episodePath+"/url.txt"
     }


     constructor(parcel: Parcel) : this() {
          filePath=parcel.readString()?:""
          fileName = parcel.readString()?:""
          uuid = parcel.readString()?:""
          m3u8IndexPath = parcel.readString()?:""
          episodePath = parcel.readString()?:""
          urlPath = parcel.readString()?:""
          resolution = parcel.readString()?:""
          urlConverter=parcel.readParcelable(M3u8DownloadOption::class.java.classLoader)
          tsConverter=parcel.readParcelable(M3u8DownloadOption::class.java.classLoader)


     }

     override fun writeToParcel(parcel: Parcel, flags: Int) {
          parcel.writeString(filePath)
          parcel.writeString(fileName)
          parcel.writeString(uuid)
          parcel.writeString(m3u8IndexPath)
          parcel.writeString(episodePath)
          parcel.writeString(urlPath)
          parcel.writeString(resolution)
          parcel.writeParcelable(urlConverter,flags)
          parcel.writeParcelable(tsConverter,flags)
     }

     override fun describeContents(): Int {
          return 0
     }

     companion object CREATOR : Parcelable.Creator<M3u8DownloadOption> {
          override fun createFromParcel(parcel: Parcel): M3u8DownloadOption {
               return M3u8DownloadOption(parcel)
          }

          override fun newArray(size: Int): Array<M3u8DownloadOption?> {
               return arrayOfNulls(size)
          }
     }

}